/*
判断一个二进制数包含几个"1", 有更快的算法吗?
*/

#include "junix.h"
uint32_t bits(uint64_t n) {
	uint32_t c=0;
	while (n) {
		c +=n & 0x01;
		n >>= 1;
	}
	return c;
}

uint32_t bits2(uint64_t n) {
	uint32_t c = 0;
	while (n) {
		++ c;
		n &= n-1;
	}
	return c;
}

int main(){
	uint64_t num=0;
	std::cout<<"Input a Number:";
	std::cin>>num;
	std::cout<<"1 bits:"<<bits2(num)<<std::endl;
}
